package com.example.weather.controller;

import com.example.weather.service.CityServiceClient;
import com.example.weather.service.SearchServiceClient;
import com.example.weather.dto.WeatherResponse;
import feign.FeignException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class ShowdataController {
    @Autowired
    CityServiceClient cityServiceClient;
    @Autowired
    SearchServiceClient searchServiceClient;

    @ResponseBody
    @RequestMapping("/show")
    public ModelAndView show(String cityid){
        ModelAndView mav = new ModelAndView("weather"); //简单名字：前缀+名字+后缀 /templates/weather.html
        System.out.println("cityid: "+cityid);
        WeatherResponse weatherResponse = searchServiceClient.searchcity(cityid);
        System.out.println("weatherResponse: "+weatherResponse);
        mav.addObject("weatherResponse",weatherResponse); //带数据去页面
        //传递城市列表数据过来
        mav.addObject("cityList",cityServiceClient.getAllCities());
        //把用户选中的城市编号传递回页面
        mav.addObject("cityid",cityid);
        return mav;
    }

}
